package com.kele.service.ExceptHandler.handler;

import com.kele.service.ExceptHandler.Exception.NameExpection;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.servlet.ModelAndView;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

/**
 * 创作人 王箫凯
 * Date 2021/6/1
 * Time 20:51
 *
 * @author 王箫凯
 */
@ControllerAdvice
public class AllInformation {
    @ExceptionHandler(value = NameExpection.class)
    public ModelAndView mv(Exception ex){
        ModelAndView view=new ModelAndView();
        view.addObject("msg","未知错误");
        view.addObject("ex",ex);
        view.setViewName("static_resources/templates/five_five");
        return view;
    }
    @ExceptionHandler(value = Exception.class)
    public ModelAndView modelAndView(Exception exception, HttpServletRequest request) throws IOException {

        ModelAndView view = new ModelAndView();
        view.addObject("msg","未知错误");
        view.addObject("ex",exception);
        String a=request.getContextPath();
        a=a.substring(a.lastIndexOf("/")+1);
        view.setViewName("static_resources/templates/five_five");
        return view;
    }
}
